package com.qf.dao.impl;

import com.qf.dao.dizhiDao;
import com.qf.pojo.TbAddress1;
import com.qf.utils.DBUtils;
import com.qf.utils.SqlUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;

public class dizhiDaoImpl implements dizhiDao {

    QueryRunner queryRunner = new QueryRunner();

    @Override
    public void adddizhi(TbAddress1 tbAddress) {
        String sql = SqlUtils.getSql("adddizhi");
        Object[] a = {tbAddress.getDetail(), tbAddress.getName(), tbAddress.getPhone(), tbAddress.getUid(), tbAddress.getLevel()};
        try {
            queryRunner.insert(DBUtils.getConnection(), sql, new ScalarHandler<>(), a);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void deletedizhi(int id) {
        String sql = SqlUtils.getSql("deletedizhi");
        try {
            queryRunner.update(DBUtils.getConnection(), sql, id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updatedizhi(TbAddress1 tbAddress) {
        String sql = SqlUtils.getSql("updatedizhi");
        Object[] a = {tbAddress.getDetail(), tbAddress.getName(), tbAddress.getPhone(), tbAddress.getUid(), tbAddress.getLevel(),tbAddress.getId()};

        try {
            queryRunner.update(DBUtils.getConnection(), sql,a);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
